<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="关键词" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入专家姓名/电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择审核状态"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="item in dict.type.ap_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb-8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['expert:ap:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="apList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="姓名"
        align="center"
        prop="userName"
        width="100"
      />
      <el-table-column label="性别" align="center" prop="sex" width="60">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="头像" align="center" prop="headimg" width="100">
        <template slot-scope="scope">
          <image-preview
            v-if="scope.row.headimg"
            :src="scope.row.headimg"
            :width="50"
            :height="50"
          />
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="mobile" width="120" />
      <el-table-column label="所属机构" align="center" prop="com" min-width="250" />

      <el-table-column label="所属科室" align="center" prop="deptName" />
      <el-table-column
        label="专家职称"
        align="center"
        prop="postName"
        width="100"
      >
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="apStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.ap_status"
            :value="scope.row.apStatus"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      />
      <el-table-column
        label="审核时间"
        align="center"
        prop="updateTime"
        width="180"
      />
      <el-table-column
        label="审核备注"
        align="center"
        prop="apText"
        width="180"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120px"
        fixed="right"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.apStatus == 2">
            <el-button
              v-hasPermi="['expert:ap:verify']"
              size="mini"
              type="text"
              icon="el-icon-s-check"
              @click="handleAdit(scope.row)"
              >审核
            </el-button>
          </span>
          <span v-else>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="handleAdit(scope.row, 'check')"
              >详情
            </el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <ApExpertDetails ref="ApExpertDetails" @refresh="getList" />
  </div>
</template>

<script>
import { getApList } from "@/api/expert/ap";
import ApExpertDetails from "./apExpertDetails"

export default {
  name: "Ap",
  dicts: ["ap_status", "sys_user_sex"],
  components: {
    ApExpertDetails
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专家审核表格数据
      apList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: "",
        type: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    /** 查询专家审核列表 */
    getList() {
      this.loading = true;
      getApList(this.queryParams).then((response) => {
        this.apList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "expert/ap/export",
        {
          ...this.queryParams,
        },
        `审核记录_${this.parseTime(new Date(), "{y}-{m}-{d}")}.xlsx`
      );
    },
    // 审核按钮操作
    handleAdit(row, type) {
      this.$refs.ApExpertDetails.openModal(row.id, type);
    }
  },
};
</script>
